package com.vdm.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class GenerationNum {
	/**
	 * 
	 * @param prefix 前缀（wmi，wmo），如果是库存批次则传入""
	 * @param length 后缀随机数长度，传入2 或者3
	 * @return
	 */
	public static String getSerialNum(String prefix,int length){
		Date now=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyMMddHHmmss");
		Random rd=new Random();
		int num;
		String suffix = "";
		if(length!=0){
			if(length==2){
				num=rd.nextInt(100);
				suffix=num<10?"0"+num:""+num;
			}else {
				num=rd.nextInt(1000);
				if(num<10){
					suffix=num<10?"00"+num:""+num;
				}else{
					suffix=num<100?"0"+num:""+num;
				}
			}
		}
		return prefix+sdf.format(now)+suffix;
	}
}
